﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRAssistant.Data;
using System.IO;
using MySql.Data.MySqlClient;

namespace HRAssistant
{
    public partial class EmployeeDataImportForm : Form
    {
        private string filepath = "";


        public EmployeeDataImportForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //if (openFileDialog1.ShowDialog() == DialogResult.OK)
            //{
            //    filepath = openFileDialog1.SafeFileName;
            //    System.IO.StreamReader sr = new System.IO.StreamReader(filepath);
            //    this.ActiveMdiChild.ActiveControl.Text = sr.ReadToEnd();
            //    sr.Close();
            //}
            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);  //定义打开的默认文件夹位置
            openFileDialog1.ShowDialog();          //显示打开文件的窗口
            filepath = openFileDialog1.FileName;               //获得选择的文件路径

            comboBox1.Text = filepath;
            //extendedName = Path.GetExtension(filepath);       //获得文件扩展名
            //fileName1 = Path.GetFileName(filepath);           //获得文件名
        }

        private void button2_Click(object sender, EventArgs e)
        {
            filepath = "C:/fts.xls";
            if (filepath != String.Empty)
            {
                DataSet ds= ReadWriteExcel.LoadDataFromExcel(filepath);
                dataGridView1.DataSource = ds.Tables[0];
                Application.DoEvents();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("khh","客户号");
            dic.Add("NEW_KHQC", "新客户卡号");
            dic.Add("NEW_JGZCRQ", "新机构时间");
            dic.Add("NEW_JGZCZB", "新机构zb");
            dic.Add("NEW_FRDBXM", "新法人xm");
            dic.Add("NEW_FRDBZJYXQ", "新法人xq");
            dic.Add("NEW_JBRXM", "新jbrxm");
            dic.Add("NEW_JBRZJYXQ", "新客户号xq");

            ReadWriteExcel.ExportTasks(dataGridView1, dic);

        }

        private void button3_Click_1(object sender, EventArgs e)
        {
             
            MySqlConnection mysqlcon;
            MySqlDataAdapter mysqldata = new MySqlDataAdapter();
            DataSet dataset = new DataSet();
            mysqlcon = new MySqlConnection("server=localhost; user id=root; password=root; database=orangehrm_mysql; pooling=false;");
            mysqldata.SelectCommand = new MySqlCommand();
            mysqldata.SelectCommand.Connection = mysqlcon;
            mysqldata.SelectCommand.CommandText = "sp_work_hour";
            mysqldata.SelectCommand.CommandType = CommandType.StoredProcedure;
            //设置参数，添加到数据库  
            //MySqlParameter startdate_parameter = new MySqlParameter("?startdate", MySqlDbType.DateTime);//mysql的存储过程参数是以?打头的！！！！  
            //startdate_parameter.Value = datet;
            //mysqldata.SelectCommand.Parameters.Add(startdate_parameter);
            ////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
            //MySqlParameter enddate_parameter = new MySqlParameter("?enddate", MySqlDbType.DateTime);//mysql的存储过程参数是以?打头的！！！！  
            //enddate_parameter.Value = email;
            //mysqldata.SelectCommand.Parameters.Add(enddate_parameter);
            ////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
            //MySqlParameter password_parameter = new MySqlParameter("?xpassword", MySqlDbType.VarChar, 100);//mysql的存储过程参数是以?打头的！！！！  
            //password_parameter.Value = password;
            //mysqldata.SelectCommand.Parameters.Add(password_parameter);
            ////++++++++++++++++++++++++++返回值++++++++++++++++++++++++++++++++++++++++++  
            //MySqlParameter id_parameter = new MySqlParameter("?xid", MySqlDbType.Int16, 15);//mysql的存储过程参数是以?打头的！！！！  
            //id_parameter.Direction = ParameterDirection.Output;
            //mysqldata.SelectCommand.Parameters.Add(id_parameter);
            ////+++++++++++++++++++++++++打开数据库，插入数据，返回id值+++++++++++++++++++  
            //try
            //{
            //    mysqldata.Fill(dataset, "yuan_user_cc");

            //    id = (Int16)id_parameter.Value;
            //    return id.ToString();
            //}
            //catch (MySqlException ex)
            //{
            //    MessageBox.Show(ex.Message);
            //    return String.Empty;
            //}   
  
        }
    }
}
